home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / fread.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  745b  |  34 lines

  1. /* fread.c 23.3 */
  2. #include<stdio.h>
  3.  
  4. #define NUM_DATA (sizeof(data)/sizeof(long))
  5.  
  6. long data[] =
  7. {
  8.   4711, 815, 1024, 1, 31415926, 0, -13, 10, 0xFFFF, 065432
  9. };
  10.  
  11. main()
  12. {
  13.   FILE *input, *output, *fopen();
  14.   int i;
  15.   long test[NUM_DATA];
  16.   char filename[81];
  17.  
  18.   printf("Please input filename!\n");
  19.   scanf("%80s", filename);
  20.   printf("Data size %d, Elements %d\n", sizeof(data), NUM_DATA);
  21.   output = fopen(filename, "wb"); /* binary! */
  22.   fwrite(data, sizeof(long), NUM_DATA, output);
  23.   fclose(output);
  24.  
  25.   printf("Read Data!\n");
  26.   input = fopen(filename, "rb");
  27.   printf("%d Elements read\n", fread(test, sizeof(long), NUM_DATA, input));
  28.   fclose(input);
  29.   for(i = 0; i < NUM_DATA; i++)
  30.     printf("%ld\t", test[i]);
  31.   printf("\nDone!\n");
  32. }
  33.  
  34.